package com.jvtd.baseProject.ui.main;



import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;

import com.jvtd.baseProject.R;
import com.jvtd.baseProject.base.BaseMvpActivity;
import com.jvtd.baseProject.bean.ui.BottomBarBean;
import com.jvtd.baseProject.ui.main.home.HomeFragment;
import com.jvtd.baseProject.ui.main.my.MyFragment;
import com.jvtd.baseProject.utils.AppIndicatorUtils;
import com.jvtd.bean.BarData;
import com.jvtd.utils.SystemUtils;
import com.jvtd.widget.viewPager.JvtdViewPager;
import com.jvtd.widget.viewPager.pagerAdapter.JvtdFragmentPagerAdapter;

import net.lucode.hackware.magicindicator.MagicIndicator;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BaseMvpActivity {

    // 再点一次退出程序时间
    private static final long WAIT_TIME = 2000L;

    @BindView(R.id.view_pager)
    JvtdViewPager viewPager;
    @BindView(R.id.magic_indicator)
    MagicIndicator magicIndicator;

    private long TOUCH_TIME = 0;

    private List<Fragment> mFragments = new ArrayList<>();
    private List<BarData> mBottomBarBeans = new ArrayList<>();
    private int mSelectIndex;

    public static Intent getIntent(Context context) {
        return new Intent(context, MainActivity.class);
    }

    @Override
    protected void initInject() {

    }

    @Override
    protected void getLayout() {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initViewAndData() {
        mBottomBarBeans.add(new BottomBarBean(getString(R.string.home_title), R.drawable.icon_empty, R.drawable.icon_back));
        mFragments.add(HomeFragment.newInstance());
        mBottomBarBeans.add(new BottomBarBean(getString(R.string.my_title), R.drawable.icon_empty, R.drawable.icon_back));
        mFragments.add(MyFragment.newInstance());

        JvtdFragmentPagerAdapter adapter = new JvtdFragmentPagerAdapter(getSupportFragmentManager(), mFragments);
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(mFragments.size());

        AppIndicatorUtils.initBarMagicIndicator(mContext, viewPager, magicIndicator, mBottomBarBeans,
                R.color.color_999, R.color.color_000, index -> mSelectIndex = index);
    }

    @Override
    public void onBackPressedSupport() {
        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
            SystemUtils.returnDesktop(mContext);
        } else {
            TOUCH_TIME = System.currentTimeMillis();
            showMessage(R.string.press_again_back_home);
        }
    }
}
